package com.hrz.lib.rxmvpdemo2.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.hrz.lib.rxmvpdemo2.BaseModule;
import com.hrz.lib.rxmvpdemo2.NetApi;
import com.hrz.lib.rxmvpdemo2.R2;
import com.hrz.lib.rxmvpdemo2.contract.second.DaggerSecondComponent;
import com.hrz.lib.rxmvpdemo2.contract.second.SecondContract;
import com.hrz.lib.rxmvpdemo2.contract.second.SecondPresenter;
import com.rxmvp.baselibrary.App;
import com.rxmvp.baselibrary.R;
import com.rxmvp.baselibrary.base.dagger.ActivityModule;
import com.rxmvp.baselibrary.base.mvp.BasePresenterActivity;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * 作者： huangRZ on 2017/1/21. 15:04
 * 邮箱：917647409@qq.com
 */
public class SecondActivity extends BasePresenterActivity<SecondPresenter> implements SecondContract.IView{

    @BindView(R2.id.tv_second)
    TextView textView;
    @BindView(R2.id.pb_second)
    ProgressBar pb;

    @Inject
    NetApi netApi;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        //全局的依赖注入
        DaggerSecondComponent.builder()
                .globalComponent(App.getGlobalComponent())
                .baseModule(new BaseModule())
                .activityModule(new ActivityModule(this, this))
                .build().inject(this);

        //利用leakCanary检测是否发生内存泄漏
        App.getRefWatcher(getApplication()).watch(this);
    }

    @Override
    public void showPB() {
        pb.setVisibility(View.VISIBLE);
    }

    @Override
    public void hidePB() {
        pb.setVisibility(View.GONE);
    }

    @Override
    public void setText(String content) {
        textView.setText(content);
    }

    public void sendEvent(View view) {
        mPresenter.sendEvent();
    }
}
